<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>校园招聘管理系统</title>
		<link type="text/css" rel="stylesheet" href="css/backend.css" />
	</head>
	<!-- RecruitInfo的id从+20开始 -->
	<body onload="loadform()">
		<div class="container">
			<div class="wrapper">
				<div class="header" style="background-color: goldenrod;">
					管理端
				</div>
				<!-- log图片 -->
				<div class="log"><img src="img/admin.jpg" style="width: 80%;"></div>
				<!-- 侧边栏 -->
				<div class="aside" style="background-color: goldenrod;">
					<ul>
						<li>
							<a href="#" onclick="loadform()">首页</a>
						</li>

						<li>
							<a href="#" onclick="addNotes()">用户管理</a>
						</li>

						<li>
							<a href="#" onclick="selectRecruitInfo()">审核企业招聘信息</a>
						</li>
					</ul>
				</div>

				<!-- 主体部分 -->
				<div class="section">

					<div id="1" class="module">
						<img src="img/首页2.jpg" style="width: 60%; margin-left: 250px;margin-top: 100px;">
					</div>
					<!-- 用户管理 -->
					<div id="2" class="module">
						<p style="float: left;position: relative;top: 50px;">学生账户:(分页查询未完善)</p>
						<div id="student" class="recruitInfoBox" style="height: 30%; background-color: bisque;">

						</div>
						<p style="margin-top: 400px;">公司账户:</p>
						<div id="company" class="recruitInfoBox" style="height: 30%;margin-top: 10px;background-color: bisque;">
							<table>
								<tr>公司账户:</tr>
							</table>
						</div>

					</div>


					<!-- 审核招聘信息/ -->
					<div id="3" class="module">
						<div id="shenghe" class="recruitInfoBox">
							<!-- <input type="button" onclick="createNewElements()" value="32322" /> -->
						</div>
					</div>





				</div>

			</div>
		</div>
	</body>
	<script src="js/login.js"></script>
	<script src="js/axios-0.18.0.js"></script>
	<script language="JavaScript">
		var companyAccount = new Array;
		var account = sessionStorage.getItem("user");
		var accountHaveValue = "false"; //判断简历是否已经写过信息,决定是update还是save

		//请求url
		var locaUrl;
		setTimeout("getLocation()");
		function getLocation(){
			// 获取当前页面的完整 URL
			var currentUrl = window.location.href;
			// 提取网段部分
			var hostname = (new URL(currentUrl)).hostname;
			// 构建 Ajax 请求的 URL
			locaUrl = "http://" + hostname; //+ ":8080/recruitInfo";
		}

		//验证是否有账户
		function yanzheng() {
			if (account == "" || account == null) {
				alert("系统错误,请重新登录");
				location = '/webapp/login.html';
				return;
			}
			console.log("1");
			console.log(account);
		}
		//打开文件时加载首页
		function loadform() {
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("1").classList.add("active");
		}

		//切换账户页面+loadNoteData(temp1)
		function addNotes() {

			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("2").classList.add("active");

			StudentAccount();
			CompanyAccount();
		}
		//账户信息
		function StudentAccount() {

			var accountBox = document.getElementById("student");
			accountBox.innerHTML = "";

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/login stu').then(result => {
				for (var i = 0; i < result.data.data.length; i++) {
					var text = document.createTextNode("账号:" + result.data.data.account);
					accountBox.appendChild(text);

					var text = document.createTextNode(",密码:" + result.data.data.password);
					accountBox.appendChild(text);


					var button1 = document.createElement("input");
					button1.type = "button";
					button1.value = "删除";
					button1.name = result.data.data.account; //将账户传给按钮的name
					// button1.title = jsonArray[i];
					button1.setAttribute("onclick", "shanchu(name)"); //事件用这个
					var link2 = document.createElement("br"); //换行一下
					accountBox.appendChild(link2); //将标题添加到页面
					accountBox.appendChild(button1);

					var hr = document.createElement("hr");
					accountBox.appendChild(hr);
				}
			})

		}

		function CompanyAccount() {
			var temp;
			var a = 0;
			var accountBox = document.getElementById("company");
			accountBox.innerHTML = "";

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/login company').then(result => {
				for (var i = 0; i < result.data.data.length; i++) {
					var text = document.createTextNode("账号:" + result.data.data[i].account);
					accountBox.appendChild(text);

					var text = document.createTextNode(",密码:" + result.data.data[i].password);
					accountBox.appendChild(text);

					var button1 = document.createElement("input");
					button1.type = "button";
					button1.value = "删除";
					button1.name = result.data.data[i].account; //将账户传给按钮的name
					// button1.title = jsonArray[i];
					button1.setAttribute("onclick", "shanchuCompany(name)"); //事件用这个
					var link2 = document.createElement("br"); //换行一下
					accountBox.appendChild(link2); //将标题添加到页面
					accountBox.appendChild(button1);


					var hr = document.createElement("hr");
					accountBox.appendChild(hr);
				}
			})
		}
		//删除功能
		function shanchu(name) {
			var account = name;

			axios.withCredentials = true;
			axios.delete(locaUrl+':8080/deleteStu/'+account).then(result => {
				alert("删除成功");
				StudentAccount();
			})

		}

		//删除功能
		function shanchuCompany(name) {
			var account = name;

			axios.withCredentials = true;
			axios.delete(locaUrl+':8080/deleteCompany/'+account).then(result => {
				alert("删除成功");
				CompanyAccount();
			})
		}




		//切换审核页面,为false才需要审核
		function selectRecruitInfo() {

			var userList = document.getElementById('shenghe');
			userList.innerHTML = "";
			var modules = document.getElementsByClassName("module");
			for (var i = 0; i < modules.length; i++) {
				modules[i].classList.remove("active");
			}
			document.getElementById("3").classList.add("active");

			axios.withCredentials = true;
			axios.get(locaUrl+':8080/recruitInfo').then(result => {
				var recruitInfoBox = document.getElementById("shenghe");
				//遍历数据输出到网页
				for (var i = 0; i <= result.data.data.length; i++) {
					if (result.data.data[i].post == "false") { //是否被管理员同意投放
						// var recruitInfo = document.createElement("p");
						var text = document.createTextNode("招聘职位:" + result.data.data[i].title);
						recruitInfoBox.appendChild(text); //将标题添加到页面



						var text = document.createTextNode("   " + "工资:" + result.data.data[i].salary);
						recruitInfoBox.appendChild(text); //将标题添加到页面


						var text = document.createTextNode("   " + "入职需求" + result.data.data[i].need);
						recruitInfoBox.appendChild(text); //将标题添加到页面



						var text = document.createTextNode("   " + "公司地址:" + result.data.data[i].address);
						recruitInfoBox.appendChild(text); //将标题添加到页面

						var text = document.createTextNode("   " + "专业:" + result.data.data[i].major);
						recruitInfoBox.appendChild(text); //将标题添加到页面

						var button1 = document.createElement("input");
						button1.type = "button";
						button1.value = "通过";
						button1.name = result.data.data[i].account; //将账户传给按钮的name
						// button1.title = jsonArray[i];
						button1.setAttribute("onclick", "tongguo(name)"); //事件用这个
						var link2 = document.createElement("br"); //换行一下
						recruitInfoBox.appendChild(link2); //将标题添加到页面
						recruitInfoBox.appendChild(button1);

						var link2 = document.createElement("hr"); //分隔一下
						recruitInfoBox.appendChild(link2);
					}
				}
			})

		}
		//审核通过,false改true
		function tongguo(name) {
			//update
			var accountCm = name;
			axios.withCredentials = true;
			axios.put(locaUrl+':8080/recruitUpdate1/' + accountCm).then(result => {
				if (result.data.code == "1") {
					alert("审核成功");
					selectRecruitInfo();
				}else if(result.data.code == "0") {
					alert(result.data.msg);
				}
			});
		}
	</script>


</html>
